package com.yd.tzkk.web;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.Toast;

public class JavaScriptInterface {
    private WebView webView;
    public JavaScriptInterface(WebView webView){
        this.webView = webView;
    }
    @JavascriptInterface
    public String version() {
        String versionName = "";
        try {
            PackageInfo packageInfo = webView.getContext().getPackageManager().getPackageInfo(webView.getContext().getPackageName(), 0);
            versionName = packageInfo.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return versionName;
    }
    @JavascriptInterface
    public void showToast(String message) {
        Toast.makeText(webView.getContext(), message, Toast.LENGTH_SHORT).show();
    }
}